package cn.cool.common;

import java.io.Serializable;
import java.util.LinkedHashMap;

public class CdResult extends LinkedHashMap<String, Object> implements Serializable {

    private static final long serialVersionUID = 1838764930357637121L;

    public static final int CODE_SUC = 0; //成功
    public static final int CODE_ERR = 1; //失败

    public CdResult() {
    }

    public CdResult(int code, String msg, Object data) {
        this.setCode(code);
        this.setMsg(msg);
        this.setData(data);
    }

    public CdResult setCode(int code) {
        this.put("code", code);
        return this;
    }

    public CdResult setMsg(String msg) {
        this.put("msg", msg);
        return this;
    }

    public CdResult setData(Object data) {
        this.put("data", data);
        return this;
    }

    public Integer getCode() {
        return (Integer)this.get("code");
    }

    public String getMsg() { return (String)this.get("msg");}

    public Object getData() { return this.get("data");}

    public static CdResult success() {
        return new CdResult(CODE_SUC, "success", null);
    }

    public static CdResult success(Object data) {
        return new CdResult(CODE_SUC, "success", data);
    }

    public static CdResult success(String msg) {
        return new CdResult(CODE_SUC, msg, null);
    }

    public static CdResult fail() {
        return new CdResult(CODE_ERR, "failure", null);
    }

    public static CdResult fail(String msg) {
        return new CdResult(CODE_ERR, msg, null);
    }

}
